class Solution(object):
    def delNodes(self, root, to_delete):
        to_delete = set(to_delete)
        self.out = []

        def search(node):
            if node.val in to_delete:
                if node.left:
                    root = search(node.left)
                    if root:
                        self.out.append(root)
                if node.right:
                    root = search(node.right)
                    if root:
                        self.out.append(root)
                return None
            else:
                if node.left:
                    node.left = search(node.left)
                if node.right:
                    node.right = search(node.right)
                return node

        node = search(root)
        if node:
            self.out.append(node)

        return self.out